package linklist;

/**
 * @author Jonny Long
 * @date 2021/2/3 15:26
 */
public class Solution61 {
    public ListNode rotateRight(ListNode head, int k) {
        if (head==null){
            return null;
        }
        ListNode q=head,p=null;
        int len=0;
        while (q!=null){
            len++;
            if (q.next==null){
                p=q;
            }
            q=q.next;
        }
        System.out.println(len);
        int pos=len-k%len-1;
        q=head;
        while (pos!=0){
            q=q.next;
            pos--;
        }
        p.next=head;
        head=q.next;
        q.next=null;
        return head;
    }
}
